package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.CallAplanInfoDto;
import com.crm.jdy.common.dto.ClientInvoiceInfoDto;
import com.crm.jdy.common.pojo.CallAplanInfo;
import com.crm.jdy.common.pojo.ClientInvoiceInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.CallAplanInfoService;
import com.crm.jdy.service.client.ClientInvoiceInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 发票信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年1月26日
*
*/
@Validated
@Api(tags = "clientInvoiceInfo", description = "发票信息")
@RestController
@RequestMapping("/clientInvoiceInfo")
public class ClientInvoiceInfoController{

    @Reference(version = "${service.version}", check = false)
    ClientInvoiceInfoService clientInvoiceInfoService;

    @RateLimit()
    @ApiOperation("发票信息")
    @PostMapping("/seleteClientInvoiceInfo")
    public ResultVo seleteClientInvoiceInfo(@RequestBody ClientInvoiceInfoDto clientInvoiceInfo){
        PageInfo<ClientInvoiceInfo> list = clientInvoiceInfoService.seleteClientInvoiceInfo(clientInvoiceInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新发票信息")
    @PostMapping("/updatCallAplanInfo")
    public ResultVo updatCallAplanInfo(@ApiParam(value = "clientInvoiceInfo", required = true)
                                       @Validated @RequestBody ClientInvoiceInfo clientInvoiceInfo){
        boolean index = clientInvoiceInfoService.updateClientInvoiceInfo(clientInvoiceInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加发票信息")
    @PostMapping("/addCallAplanInfo")
    public ResultVo addCallAplanInfo(@ApiParam(name = "clientInvoiceInfo", required = false)
                                     @Validated @RequestBody ClientInvoiceInfo clientInvoiceInfo){
        boolean list  = clientInvoiceInfoService.addClientInvoiceInfo(clientInvoiceInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除发票信息")
    @DeleteMapping("deleteCallAplanInfo/{invoiceId}")
    public ResultVo deleteCallAplanInfo(@NotNull @ApiParam(name = "invoiceId", value = "invoiceId", required = true) @PathVariable String invoiceId){
        boolean b = clientInvoiceInfoService.removeClientInvoiceInfo(invoiceId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }

}